<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{$Think.config.site.title} - 地推添加</title>
    <meta name="keywords" content="{$Think.config.site.keywords}">
    <meta name="description" content="{$Think.config.site.description}">
    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.min.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.min.css?v=4.0.0" rel="stylesheet">
    <link rel="stylesheet" href="https://unpkg.com/element-ui@2.4.4/lib/theme-chalk/index.css">
    <!-- import Vue before Element -->
    <script src="{$Think.config.site.resource_url}js/assets/vue.js"></script>
    <!-- import JavaScript -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>

</head>

<body class="">
<style>
    .el-upload__input{
        display: none !important;
    }
</style>
    <div class="wrapper wrapper-content animated fadeInRight">
        <form method="post" class="form-horizontal" action="" id="myformdata" enctype="multipart/form-data">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">{:lang('地推姓名')}</label>
                                <input type="hidden" name="id" value="{$info.id|default=''}">
                                <div class="col-sm-7">
                                    <input type="text"  maxlength="20" class="form-control" name="real_name" value="{$info.real_name|default=''}" id="real_name" placeholder="{:lang('输入')}{:lang('真实姓名')}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">{:lang('电话号码')}</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" value="{$info.phone|default=''}" name="phone" id="phone" placeholder="{:lang('输入')}{:lang('电话')}" maxlength="11">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">{:lang('所属于代理商')}</label>
                                <label class="col-sm-7">
                                    <select data-placeholder="选择代理商......" class="chosen-select  form-control" id='oid' name="belong_agent" style="width:150px;" tabindex="2">
                                        <option value="">{:lang('选择代理商')}</option>
                                        {volist name="agent" id="vo"}
                                        <?php if (isset($info['belong_agent']) && $info['belong_agent'] == $vo['id'])  {?>
                                        <option value="{$vo.id}" hassubinfo="true" selected>{$vo.agent_name}</option>
                                        <?php }else { ?>
                                        <option value="{$vo.id}" hassubinfo="true" >{$vo.agent_name}</option>
                                        <?php } ?>
                                        {/volist}
                                    </select>
                                </label>
                            </div>


                            <div class="form-group">
                                <label class="col-sm-2 control-label">{:lang('身份证号')}</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" id="card_sn" name="card_sn" value="{$info.card_sn|default=''}" placeholder="{:lang('输入')}{:lang('身份证号')}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">{:lang('证件照')}</label>
                                <div class="col-sm-7" id="app">
                                    <el-upload name="img_file" value="fileList2" class="upload-demo" action="/ausadmin/Agent/file_upload" :on-preview="handlePreview" :on-remove="handleRemove" :on-success="handleSuccess" :file-list="fileList2" :on-error="handleError" :limit="3"  list-type="picture">
                                        <el-button size="small" type="primary" class="fl">点击上传</el-button>
                                        <div slot="tip" class="el-upload__tip load_notice" style="font-weight: bold;color:red">
                                            {:lang('只能上传jpg/png文件，且不超过2M(请上传身份证正面、反面、手持身份证)')}
                                        </div>
                                    </el-upload>
                                </div>
                            </div>
                            <input type="hidden" id="card_pic" name="card_pic" value="{$card_pic|default=''}">

                            <div class="form-group">
                                <label class="col-sm-2 control-label">{:lang('用户状态')}</label>
                                <label class="col-sm-7">
                                    <select data-placeholder="选择地推状态" class="chosen-select  form-control" id='status' name="status" style="width:150px;" tabindex="2">
                                        <option value="">{:lang('选择状态')}</option>
                                        {volist name="status" key="kk" id="vo"}
                                        <option value="{$kk}" hassubinfo="true" <?php if (isset($info['is_use']) && $kk == $info['is_use']) echo "selected";?>>{$vo}</option>
                                        {/volist}
                                    </select>
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-12">
                    <div class="form-group">
                        <div class="col-sm-5 col-sm-offset-5">
                            <input type="button" class="btn btn-primary" value="{:lang('提交')}" id="onbtn">
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>

    <script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
    <script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/validate/jquery.validate.min.js"></script>
<script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/validate/messages_zh.min.js"></script>
</body>

</html>
<script>
    var Main = {
        data() {
            return {
                fileList2: {$all_image}
                // fileList2: [{name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}]
            };
        },
        methods: {
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePreview(file) {
                console.log(file);
            },
            handleSuccess(response, file, fileList) {
                var data = [];
                for( var i = 0; i < fileList.length; i++){
                    data[i] = fileList[i].response.url;
                }
                data = data.join(',');
                $('#card_pic').val(data);
            },
            handleError(err, file, fileList) {
                console.log(err)
            }
        }
    }
    var Ctor = Vue.extend(Main)
    new Ctor().$mount('#app')


$(document).ready(function(){
    $("#uploadfile").on("fileuploaded", function (event,data) {
        $('#card_pic').val($('#card_pic').val()+"\n"+data.response.data);
        return true;
    });


    $('#onbtn').click(function(){
        var agent_name = $('#agent_name').val();
        var phone = $('#phone').val();
        var area = $('#area').val();
        if(agent_name==''){
            $('#agent_name').focus();
            return false;
        }
        if(phone==''){
            $('#phone').focus();
            return false;
        }
        if(area==''){
            $('#area').focus();
            return false;
        }

		//var fomrData = $("#myformdata").serialize();
        var formData = new FormData($( "#myformdata" )[0]);
		var action = "{$action}";
		$.ajax({
			type : 'POST',
			url : '<?php echo \think\Request::instance()->root(); ?>/ausadmin/Agent/'+action,
			data: formData, 
            async: false, 
            cache: false, 
            contentType: false, 
            processData: false, 
			success : function(result) {
                //layer.close(layer1);
                if(0 === result.code) {
                    layer.msg(result.msg, {icon: 1});
                    parent.location.reload();
                }  else  {
                    //删除失败
                    layer.msg(result.msg, {icon: 5});
                }
            },
            error : function(){
                res = false;
                layer.msg("{:lang('服务器错误！请稍后重试')}", {icon: 2});
            }
		})
	});
})
</script>

